package com.me.libgdx_test;

import java.util.ArrayList;

public class ClassAnimationIterator {
	private int animation_index, duration, duration_counter;
	private ArrayList<String> animation;
	private Point start_location, end_location;
	boolean start_converted;
	private ClassLogDisplay logger;
	private int animation_size;
	
	public class Constants{
    	static final int ANIMATION_LONG	= 3;
    	static final int ANIMATION_NORMAL = 1;
    	static final int ANIMATION_SHORT = 1;
    }
	
	ClassAnimationIterator(Point start_location, ArrayList<String> animation, int duration, int animation_size){
		this.animation = new ArrayList<String>(animation);
		this.start_location = start_location;
		this.end_location = start_location;
		animation_index = 0;
		this.duration = duration;
		this.animation_size = animation_size;
		duration_counter = duration;
		start_converted = false;
		logger = new ClassLogDisplay("ClassAnimationIterator");
	}
	ClassAnimationIterator(Point start_location, Point end_location, ArrayList<String> animation, int duration, int animation_size){
		this.animation = new ArrayList<String>(animation);
		this.start_location = start_location;
		this.end_location = end_location;
		animation_index = 0;
		this.duration = duration;
		this.animation_size = animation_size;
		duration_counter = duration;
		start_converted = false;
		logger = new ClassLogDisplay("ClassAnimationIterator");
	}
	public int get_animation_size(){
		return animation_size;
	}
	public void set_start(Point start){
		start_location = start;
	}
	public Point get_start(){
		return start_location;
	}
	public Point get_intermediate_point(){
		logger.print("Start/Finish");
		logger.print(start_location);
		logger.print(end_location);
		
		float difference_x = end_location.x - start_location.x;
		float difference_y = end_location.y - start_location.y;
		logger.print("Point Difference");
		logger.print(new Point((int)difference_x, (int) difference_y));
		
		float size_difference = (float)animation_index/(float)animation.size();
		
		Point intermediate_point = new Point((int)(difference_x*size_difference + start_location.x),(int)(difference_y*size_difference + start_location.y));
		logger.print("Intermediate Point: " + intermediate_point);
		return intermediate_point;
	}
	public boolean animation_moving(){
		return !start_location.equals(end_location);
	}
	public String get_frame(){
		String frame = animation.get(animation_index);
		logger.print("Current_Frame: " + animation_index);
		logger.print("Frame String: " + frame);
		duration_counter--;
		if(duration_counter == 0){
			duration_counter = duration;
			animation_index++;
		}
		return frame;
	}
	public Point get_location(){
		return start_location;
	}
	public boolean animation_over(){
		return animation_index == animation.size();
	}
}
